#!/bin/bash
SCRIPT_DIR=$(cd "$(dirname "$0")" && pwd)
SFTP_TOOL="$SCRIPT_DIR/../tools/sftp"

if [ ! -f ${SCRIPT_DIR}/cri-resmgr ]; then
    if [ ! -f "$SFTP_TOOL" ]; then
        if [ ! -f ./sftp ]; then
            wget https://gitee.com/anolis/hygon-devkit/raw/master/tools/sftp
        fi
        chmod +x sftp
        ./sftp download /hygon-devkit/4.0/2025-01-01/cri-rm/cri-resmgr ${SCRIPT_DIR}/cri-resmgr
    else
        $SFTP_TOOL download /hygon-devkit/4.0/2025-01-01/cri-rm/cri-resmgr ${SCRIPT_DIR}/cri-resmgr
    fi
fi

if [ $? -eq 0 ]; then
    chmod +x ${SCRIPT_DIR}/cri-resmgr
    cp -r ${SCRIPT_DIR}/cri-resmgr /usr/bin/
fi